package com.example.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCExample {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //注册驱动类
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接对象 连接数据库
        String dataBaseUrl = "jdbc:mysql://localhost:3306/testdb";
        String user  = "root";
        String  password="123456";
        //获取连接对象
        Connection conn = DriverManager.getConnection(dataBaseUrl, user, password);
        //定义SQL语句
        String updateSQL ="UPDATE account SET money = 3010 WHERE id = 1";
        //获取SQL执行对象
        Statement statement = conn.createStatement();
        //执行SQL语句
        int i = statement.executeUpdate(updateSQL);
        if (i>0){
            System.out.println("更新成功");
        }
        //释放资源
        statement.close();
        conn.close();
    }
}
